<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\widgets\Datetimepicker;

Datetimepicker::widget(['timepicker' => 'true', 'datepicker' => 'false', 'format' => 'H:i', 'step' => '5']);
?>
    <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'options' => ['class' => 'form-validate']]); ?>
    <table width="100%" class="table-form">
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['total']; ?></th>
            <td><?= $form->field($model, 'total', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <?php if(!empty($payList)) { ?>
            <?php foreach ($payList as $pay) { ?>
                <tr>
                    <th class="zx-goods-table"><?=$pay['name']?></th>
                    <td>
                        <?=Html::textInput("pay[$pay[code]]",null,['class'=>'extend_required input-text'])?>
                        <div class="help-block"></div>
                    </td>
                </tr>
            <?php } ?>
        <?php }?>
    </table>
    <div class="yx-submit-box" style="display: none">
        <?= \yii\helpers\Html::buttonInput( '提交', ['class' => "button yx-submit", 'id' => 'dosubmit']) ?>
    </div>

<?php \yii\widgets\ActiveForm::end(); ?>
<?php
$js = <<<JS
   $(document).on('click','#dosubmit',function(){
       var tmp = true;
       var totla = parseFloat($('#customerrecharge-total').val());
       var money = 0;
       $('.extend_required').each(function(e){
           var val = $.trim($(this).val())!= '' ?parseFloat($.trim($(this).val())):0;
           money += val;
      });
       if(money == totla){
          $('.form-validate').submit();
       }else {
           $('.extend_required:last').next().html('支付金额等于充值合金额！');
       }
   });

  $('.extend_required').blur(function() {
        var val = $(this).val();
        var reg = /^[-\+]?\d+(\.\d+)?$/;
        if(!reg.test(val)){
            $(this).next().html('只能为数字');
        }else {
            $(this).next().html('');
               var totla = parseFloat($('#customerrecharge-total').val());
               var money = 0;
               $('.extend_required').each(function(e){
                   var val = $.trim($(this).val())!= '' ?parseFloat($.trim($(this).val())):0;
                   money += val;
              });
               if(money == totla){
                  $('.extend_required:last').next().html('');
               }
        }
  });
    
JS;
$this->registerJS($js);
?>
